package spider.hysrlzy.mapper;

import com.yc.favorite.util.MyBatisHelper;
import spider.DataDao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CategroyDao implements DataDao<List<Map<String, String>>> {

    @Override
    public void save(List<Map<String, String>> list) {
        MyBatisHelper.execute(s->{
            for(Map<String,String> map : list){
                CategoryMapper mapper = s.getMapper(CategoryMapper.class);
                mapper.insert(map);   //  ? error
                Object pid = map.get("id");
                String children = map.get("children");
                String[] childs = children.split("\\n");
                for(String child : childs){
                    Map<String, String> childMap = new HashMap<>();
                    childMap.put("name", child);
                    childMap.put("pid", pid + "");
                    mapper.insert(childMap);
                }
            }
            return null;
        });
    }
}
